//
//  ViewController.swift
//  WeixinDemo
//
//  Created by yao_yu on 14-8-15.
//  Copyright (c) 2014年 yao_yu. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
                            
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        view.backgroundColor = UIColor.whiteColor()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func bubbleView(text:NSString, from:Bool, withPosition:Int) -> UIView{
        let font = UIFont.systemFontOfSize(14)
        let attributes = [NSFontAttributeName: font]
        let size = text.boundingRectWithSize(CGSizeMake(180, 20000), options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: attributes, context: nil)
        let resView = UIView(frame: size)
        resView.backgroundColor = UIColor.clearColor()
        let bubble = UIImage()//
        let bubbleImageView = UIImageView(image: bubble.stretchableImageWithLeftCapWidth(Int( bubble.size.width/2.0), topCapHeight: Int(bubble.size.height/2.0)))
        
        let bubbleText = UILabel(frame: <#CGRect#>)
    }

}



//
////泡泡文本
//- (UIView *)bubbleView:(NSString *)text from:(BOOL)fromSelf withPosition:(int)position{
//    
//    //计算大小
//    UIFont *font = [UIFont systemFontOfSize:14];
//    CGSize size = [text sizeWithFont:font constrainedToSize:CGSizeMake(180.0f, 20000.0f) lineBreakMode:NSLineBreakByWordWrapping];
//    
//    // build single chat bubble cell with given text
//    UIView *returnView = [[UIView alloc] initWithFrame:CGRectZero];
//    returnView.backgroundColor = [UIColor clearColor];
//    
//    //背影图片
//    UIImage *bubble = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fromSelf?@"SenderAppNodeBkg_HL":@"ReceiverTextNodeBkg" ofType:@"png"]];
//    
//    UIImageView *bubbleImageView = [[UIImageView alloc] initWithImage:[bubble stretchableImageWithLeftCapWidth:floorf(bubble.size.width/2) topCapHeight:floorf(bubble.size.height/2)]];
//    NSLog(@"%f,%f",size.width,size.height);
//    
//    
//    //添加文本信息
//    UILabel *bubbleText = [[UILabel alloc] initWithFrame:CGRectMake(fromSelf?15.0f:22.0f, 20.0f, size.width+10, size.height+10)];
//    bubbleText.backgroundColor = [UIColor clearColor];
//    bubbleText.font = font;
//    bubbleText.numberOfLines = 0;
//    bubbleText.lineBreakMode = NSLineBreakByWordWrapping;
//    bubbleText.text = text;
//    
//    bubbleImageView.frame = CGRectMake(0.0f, 14.0f, bubbleText.frame.size.width+30.0f, bubbleText.frame.size.height+20.0f);
//    
//    if(fromSelf)
//    returnView.frame = CGRectMake(320-position-(bubbleText.frame.size.width+30.0f), 0.0f, bubbleText.frame.size.width+30.0f, bubbleText.frame.size.height+30.0f);
//    else
//    returnView.frame = CGRectMake(position, 0.0f, bubbleText.frame.size.width+30.0f, bubbleText.frame.size.height+30.0f);
//    
//    [returnView addSubview:bubbleImageView];
//    [returnView addSubview:bubbleText];
//    
//    return returnView;
//    }
//    
//    //泡泡语音
//    - (UIView *)yuyinView:(NSInteger)logntime from:(BOOL)fromSelf withIndexRow:(NSInteger)indexRow  withPosition:(int)position{
//        
//        //根据语音长度
//        int yuyinwidth = 66+fromSelf;
//        
//        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//        button.tag = indexRow;
//        if(fromSelf)
//        button.frame =CGRectMake(320-position-yuyinwidth, 10, yuyinwidth, 54);
//        else
//        button.frame =CGRectMake(position, 10, yuyinwidth, 54);
//        
//        //image偏移量
//        UIEdgeInsets imageInsert;
//        imageInsert.top = -10;
//        imageInsert.left = fromSelf?button.frame.size.width/3:-button.frame.size.width/3;
//        button.imageEdgeInsets = imageInsert;
//        
//        [button setImage:[UIImage imageNamed:fromSelf?@"SenderVoiceNodePlaying":@"ReceiverVoiceNodePlaying"] forState:UIControlStateNormal];
//        UIImage *backgroundImage = [UIImage imageNamed:fromSelf?@"SenderVoiceNodeDownloading":@"ReceiverVoiceNodeDownloading"];
//        backgroundImage = [backgroundImage stretchableImageWithLeftCapWidth:20 topCapHeight:0];
//        [button setBackgroundImage:backgroundImage forState:UIControlStateNormal];
//        
//        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(fromSelf?-30:button.frame.size.width, 0, 30, button.frame.size.height)];
//        label.text = [NSString stringWithFormat:@"%d''",logntime];
//        label.textColor = [UIColor grayColor];
//        label.font = [UIFont systemFontOfSize:13];
//        label.textAlignment = NSTextAlignmentCenter;
//        label.backgroundColor = [UIColor clearColor];
//        [button addSubview:label];
//        
//        return button;
//    }